<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>订单显示页面</title>
<link rel="stylesheet" href="<%=basePath %>/res/wsz/js/layui/css/layui.css" media="all">
<script type="text/javascript" src="<%=basePath %>/res/wsz/js/base.js"></script>
<style type="text/css">
	body{
		margin:20px 0px;
	}
</style>
<base href="<%=basePath %>">
</head>
<body>
	<div class="demoTable">
	  搜索:
	  <div class="layui-inline">
	    <input class="layui-input" name="indentName" id="demoReload" autocomplete="off" placeholder="输入关键字(订单号)">
	  </div>
	  <button class="layui-btn" data-type="reload">搜索</button>
	</div>
	<table class="layui-hide" id="fodIndent" lay-filter="demo"></table>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="ps">派送</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
 
<script src="<%=basePath %>/res/wsz/js/layui/layui.js"></script>
<script>

layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
	  var laydate = layui.laydate //日期
	  ,laypage = layui.laypage //分页
	  layer = layui.layer //弹层
	  ,table = layui.table //表格
	  ,upload = layui.upload //上传
	  ,element = layui.element; //元素操作
	 
	  
	  //监听Tab切换
	  element.on('tab(demo)', function(data){
	    layer.msg('切换了：'+ this.innerHTML);
	    console.log(data);
	  });
	  
	  //执行一个 table 实例
	  table.render({
	     elem: '#fodIndent'
	    ,height: 440
	    ,url: '<%=basePath %>fodIndent/findAll' //数据接口
	    ,page: true //开启分页
	    ,method:'post'
	    ,cols: [[ //表头
	       {type:'checkbox', fixed: 'left'}
	      ,{field: 'indent_id', title: '订单ID', width:80, fixed: 'left'}
	      ,{field: 'merchant_name', title: '商家名称', width:90}
	      ,{field: 'user_name', title: '用户名称', width:100}
	      ,{field: 'user_phone', title: '用户电话', width:150}
	      ,{field: 'indent_name', title: '收货地址', width:150}
	      ,{field: 'indent_num', title: '订单总数量', width:100}
	      ,{field: 'indent_price', title: '订单总价格', width: 100}
	      ,{field: 'isva', title: '是否有效', width: 100}
	      ,{field: 'optime', title: '操作时间', width: 120}
	      ,{field: 'pay', title: '支付状态', width: 90}
	      ,{field: 'dis', title: '配送状态', width: 90}
	      ,{fixed: 'right',title: '操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
	  	,id: 'testReload'
	  });
	  
	  
	  sessionStorage["stockId"]="";

//监听工具条
	table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
		var data = obj.data //获得当前行数据
				,layEvent = obj.event; //获得 lay-event 对应的值
		if(layEvent === 'del'){
			var indentId=data.indent_id;
			layer.confirm('确认删除？', function(index){

				layer.close(index);
				//使用jquery的ajax方式向后台提交数据
				var url = "<%=basePath %>fodIndent/updateById";
				var data={indentId:indentId};
				$.post(url,data,function(data){
					layer.msg('删除成功', {
						icon: 1,
						time: 1000 //1秒关闭（如果不配置，默认是3秒）
					}, function(){
						obj.del();
					});

				});
			});
		} else if(layEvent === 'ps'){
			var indentId=data.indent_id;
			layer.confirm('确认派送?', function(index){
				layer.close(index);
				//使用jquery的ajax方式向后台提交数据
				var url = "<%=basePath %>fodIndent/updatePsById";
				var data={indentId:indentId};
				$.post(url,data,function(data){
						layer.msg('派送成功', {
							icon: 1,
							time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
							// obj.data.dis.innerHTML = "已派送";
							location.reload(); // 页面刷新
						});

				});
			});
		    }else if(layEvent==='detail'){
			    	var indent_id=data.indent_id;
			    	
			    	sessionStorage["indentId"]=indent_id;
			    	//location.href="pages/wsz/FodDetailList.jsp";
			    	
		   	    	layer.open({
		   	 			  type: 2,
		   	 			  area : ['76%' , '75%'],//弹出框大小
		   	 			  shift:1,//弹出框动画效果
		   	 			  content: ['pages/wsz/FodDetailList.jsp','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			   	 	});
			}
		});
	  
	  //条件查询
	  var $ = layui.$;
			  
	  $('.demoTable .layui-btn').on('click', function(){
		 var demoReload = $('#demoReload');
		 //执行重载
	     table.reload('testReload', {
	     	url:"<%=basePath %>fodIndent/findFodIndentsByName",
	       page: 1, //重新从第 1 页开始
	       where: {
	    	   indent_name: demoReload.val()
	       }
	     });
	  });
	  $('#fodIndentAdd').on('click', function(){
		 layer.open({
			  type: 	2,
			  area : ['60%' , '80%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: ['fodIndentAdd.jsp','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			}); 
	   });
	});
	  
</script>
</body>
</html>